﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Woodstock.Common
{
    public class SpatialState : INotifyPropertyChanged
    {
        #region OLD Channels

        /*

        private double _channel1;
        public double Channel1
        {
            get { return _channel1; }
            set { _channel1 = value; NotifyPropertyChanged("Channel1"); }
        }

        private double _channel2;
        public double Channel2
        {
            get { return _channel2; }
            set { _channel2 = value; NotifyPropertyChanged("Channel2"); }
        }

        private double _channel3;
        public double Channel3
        {
            get { return _channel3; }
            set { _channel3 = value; NotifyPropertyChanged("Channel3"); }
        }

        private double _channel4;
        public double Channel4
        {
            get { return _channel4; }
            set { _channel4 = value; NotifyPropertyChanged("Channel4"); }
        }

        private double _channel5;
        public double Channel5
        {
            get { return _channel5; }
            set { _channel5 = value; NotifyPropertyChanged("Channel5"); }
        }

        private double _channel6;
        public double Channel6
        {
            get { return _channel6; }
            set { _channel6 = value; NotifyPropertyChanged("Channel6"); }
        }

        private double _channel7;
        public double Channel7
        {
            get { return _channel7; }
            set { _channel7 = value; NotifyPropertyChanged("Channel7"); }
        }

        private double _channel8;
        public double Channel8
        {
            get { return _channel8; }
            set { _channel8 = value; NotifyPropertyChanged("Channel8"); }
        }

        private double _channel9;
        public double Channel9
        {
            get { return _channel9; }
            set { _channel9 = value; NotifyPropertyChanged("Channel9"); }
        }

        private double _channel10;
        public double Channel10
        {
            get { return _channel10; }
            set { _channel10 = value; NotifyPropertyChanged("Channel10"); }
        }

        private double _channel11;
        public double Channel11
        {
            get { return _channel11; }
            set { _channel11 = value; NotifyPropertyChanged("Channel11"); }
        }

        private double _channel12;
        public double Channel12
        {
            get { return _channel12; }
            set { _channel12 = value; NotifyPropertyChanged("Channel12"); }
        }

         */ 
         
        #endregion

        #region Enviromental Spatial State

        //
        // GPS
        //
        private string _latitude;
        public string Latitude
        {
            get { return _latitude; }
            set { _latitude = value; NotifyPropertyChanged("Latitude"); }
        }

        private string _longitude;
        public string Longitude
        {
            get { return _longitude; }
            set { _longitude = value; NotifyPropertyChanged("Longitude"); }
        }

        private double _altitude;
        public double Altitude
        {
            get { return _altitude; }
            set { _altitude = value; NotifyPropertyChanged("Altitude"); }
        }

        private DateTime _DateTime;
        public DateTime DateTime
        {
            get { return _DateTime; }
            set { _DateTime = value; NotifyPropertyChanged("DateTime"); }
        }



        //
        // Accelerometer data in Gs
        //
        private double _xAcceleration;
        public double XAcceleration
        {
            get { return _xAcceleration; }
            set { _xAcceleration = value; NotifyPropertyChanged("XAcceleration"); }
        }

        private double _yAcceleration;
        public double YAcceleration
        {
            get { return _yAcceleration; }
            set { _yAcceleration = value; NotifyPropertyChanged("YAcceleration"); }
        }


        private double _zAcceleration;
        public double ZAcceleration
        {
            get { return _zAcceleration; }
            set { _zAcceleration = value; NotifyPropertyChanged("ZAcceleration"); }
        }

        //
        // Gyro data in degrees/s
        //
        private double _xAngularRate;
        public double XAngularRate
        {
            get { return _xAngularRate; }
            set { _xAngularRate = value; NotifyPropertyChanged("XAngularRate"); }
        }

        private double _yAngularRate;
        public double YAngularRate
        {
            get { return _yAngularRate; }
            set { _yAngularRate = value; NotifyPropertyChanged("YAngularRate"); }
        }

        private double _zAngularRate;
        public double ZAngularRate
        {
            get { return _zAngularRate; }
            set { _zAngularRate = value; NotifyPropertyChanged("ZAngularRate"); }
        }



        // Still needed?
        private double _xAngle;
        public double XAngle
        {
            get { return _xAngle; }
            set { _xAngle = value; NotifyPropertyChanged("XAngle"); }
        }

        private double _yAngle;
        public double YAngle
        {
            get { return _yAngle; }
            set { _yAngle = value; NotifyPropertyChanged("YAngle"); }
        }

        private double _zAngle;
        public double ZAngle
        {
            get { return _zAngle; }
            set { _zAngle = value; NotifyPropertyChanged("ZAngle"); }
        }


        private double _compass;
        public double Compass
        {
            get { return _compass; }
            set { _compass = value; NotifyPropertyChanged("Compass"); }
        }



        //
        // Filtered data (manipulated by the filter in duty). Based on Gyro, Accelerometer and Magnetometer data
        //
        private double _roll;
        public double Roll
        {
            get { return _roll; }
            set { _roll = value; NotifyPropertyChanged("Roll"); }
        }

        private double _pitch;
        public double Pitch
        {
            get { return _pitch; }
            set { _pitch = value; NotifyPropertyChanged("Pitch"); }
        }

        private double _yaw;
        public double Yaw
        {
            get { return _yaw; }
            set { _yaw = value; NotifyPropertyChanged("Yaw"); }
        }



        // TODO: Magnetometer, Barometer, Compass


        #endregion




        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public override string ToString()
        {
            StringBuilder controllerString = new StringBuilder();

            foreach (var prop in GetType().GetProperties())
            {
                if (prop.CanRead)
                {
                    controllerString.Append(prop.Name + ":" + prop.GetValue(this, null).ToString() + "|");
                }
            }

            return controllerString.ToString();
        }
    }
}
